'use strict';
var car;
var Server = require('home').Server;
var server = new Server();

server.get('/forward', function(req, res) {
    car.forward();
    res.end();
});

server.get('/backward', function (req, res) {
    car.backward();
    res.end();
});

server.get('/turn-left', function (req, res) {
    car.turnLeft();
    res.end();
});

server.get('/turn-right', function (req, res) {
    car.turnRight();
    res.end();
});

server.get('/stop', function (req, res) {
    car.stop();
    res.end();
});
$.ready(function (error) {
    if (error) {
        console.log(error);
        return;
    }
    car = $('#car');
    car.setSpeed(60);
    server.listen(6318);

    $('#led-r').turnOn();    
});

$.end(function () {
    $('#led-r').turnOff();
});
